﻿namespace ThreeByte.ActiveDeck.Dashboard
{
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using System;
    using ActiveDeck.Dashboard.LoginUI;
    using ThreeByte.ActiveDeck.Web.Services;
    using System.ServiceModel.DomainServices.Client;
    using ThreeByte.ActiveDeck.Web.Models;
    using System.Xml.Linq;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    using System.Linq;

    /// <summary>
    /// Home page for the application.
    /// </summary>
    public partial class ErrorReport : Page
    {

        public static readonly XNamespace NAMESPACE = @"http://www.activedeck.com/PowerPoint/";
        public static readonly XNamespace ns = NAMESPACE;

        /// <summary>
        /// Creates a new <see cref="Inspect"/> instance.
        /// </summary>
        public ErrorReport() {
            InitializeComponent();
                      
        }

        /// <summary>
        /// Executes when the user navigates to this page.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e) {
            //Get the Query parameters

            try {
                string id = this.NavigationContext.QueryString["id"];
                LoadReport(Guid.Parse(id));
            } catch(Exception) {
                ReportText.Text = @"Error loading the report.  Please make sure the report ID is valid.";
            }
        }

        private DashboardDataContext ctx = new DashboardDataContext();

        private void LoadReport(Guid id) {

            //Load the ErrorReport
            ctx.GetErrorReport(id, ReportLoadComplete, id);
        }

        private void ReportLoadComplete(InvokeOperation<string> op) {

            //After we got the PresentationConfig, do something with it
            if(op.HasError) {
                //Handle this
                ReportText.Text = @"Error loading the report";
                return;
            }

            ReportText.Text = op.Value;
           
        }


    }
}